<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修复后的导出测试</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet">
</head>
<body>
    <div class="container mt-4">
        <h1>修复后的导出功能测试</h1>
        
        <div class="alert alert-info">
            <strong>说明：</strong>这个页面用于测试修复后的导出功能。请确保您已经在线索管理页面登录并获得token。
        </div>
        
        <div class="card">
            <div class="card-header">
                <h5>测试步骤</h5>
            </div>
            <div class="card-body">
                <ol>
                    <li>在线索管理页面 (<a href="/admin/clues.html" target="_blank">clues.html</a>) 登录</li>
                    <li>回到本页面，点击下面的测试按钮</li>
                    <li>检查浏览器控制台输出</li>
                    <li>验证导出功能是否正常工作</li>
                </ol>
                
                <div class="mt-3">
                    <button class="btn btn-primary me-2" onclick="testExportJS()">测试外部JS调试</button>
                    <button class="btn btn-success me-2" onclick="testDirectExport()">测试直接导出</button>
                    <button class="btn btn-info" onclick="openCluesPageTest()">打开线索页面测试</button>
                </div>
                
                <div id="testResults" class="mt-3"></div>
            </div>
        </div>
        
        <div class="card mt-3">
            <div class="card-header">
                <h5>问题排查指南</h5>
            </div>
            <div class="card-body">
                <h6>如果导出还是不工作，请检查：</h6>
                <ul>
                    <li><strong>浏览器控制台</strong>：按F12查看是否有JavaScript错误</li>
                    <li><strong>网络面板</strong>：检查外部JS文件是否成功加载</li>
                    <li><strong>选中状态</strong>：确保能正常选中线索复选框</li>
                    <li><strong>按钮状态</strong>：导出按钮应该在选中线索后变为可用状态</li>
                </ul>
                
                <h6>调试命令（在线索管理页面的控制台中执行）：</h6>
                <div class="bg-light p-2 mt-2">
                    <code>
                        // 调试外部JS状态<br>
                        debugExportJS()<br><br>
                        
                        // 测试选择功能<br>
                        selectTestClues()<br><br>
                        
                        // 测试导出功能<br>
                        testExport()
                    </code>
                </div>
            </div>
        </div>
    </div>
    
    <script>
        function testExportJS() {
            const results = document.getElementById('testResults');
            results.innerHTML = '<div class="alert alert-warning">测试中...</div>';
            
            try {
                // 检查外部JS是否加载
                if (typeof window.debugExportJS === 'function') {
                    const debugInfo = window.debugExportJS();
                    results.innerHTML = `
                        <div class="alert alert-success">
                            <h6>外部JS已加载！</h6>
                            <pre>${JSON.stringify(debugInfo, null, 2)}</pre>
                        </div>
                    `;
                } else {
                    results.innerHTML = `
                        <div class="alert alert-danger">
                            <h6>外部JS未加载！</h6>
                            <p>请在线索管理页面测试，或检查JS文件路径</p>
                        </div>
                    `;
                }
            } catch (error) {
                results.innerHTML = `
                    <div class="alert alert-danger">
                        <h6>测试失败：</h6>
                        <p>${error.message}</p>
                    </div>
                `;
            }
        }
        
        function testDirectExport() {
            const results = document.getElementById('testResults');
            const token = localStorage.getItem('adminToken');
            
            if (!token) {
                results.innerHTML = `
                    <div class="alert alert-warning">
                        <h6>没有找到Token</h6>
                        <p>请先在线索管理页面登录</p>
                    </div>
                `;
                return;
            }
            
            const exportUrl = `/api/admin/clues/export?format=excel&clue_ids=1,2&token=${encodeURIComponent(token)}`;
            
            results.innerHTML = `
                <div class="alert alert-info">
                    <h6>直接导出测试</h6>
                    <p>Token已找到，尝试导出...</p>
                    <a href="${exportUrl}" class="btn btn-primary" download>点击下载测试文件</a>
                </div>
            `;
        }
        
        function openCluesPageTest() {
            window.open('/admin/clues.html', '_blank');
        }
    </script>
</body>
</html> 